<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>




<span><span>企业通讯录管理</span> | <a href="<?php echo url('user/ImportFromExcel'); ?>" >通讯录批量导入</a> | <a href="<?php echo url('telephonebook/addsignaluser'); ?>"> 单条电话添加</a></span>

<form action="<?php echo url('telephonebook/delete'); ?>" method="post" name="mainform" enctype="multipart/form-data" >
	<table cellpadding="0" cellspacing="0" width="100%" id="disp_table" name="disp_table">  

	<tbody class="">
		<tr class="tth">
		<td width="30%">名字</td>
		<td width="30%">手机号码</td>
		<td width="30%">办公室电话</td>
		<td width="*"></td>
	</tr>
		<?php foreach ($books as $coll): ?>
			<tr>
                <?php if(strlen($coll->user_realname)> 0): ?>
				<td width="30%"><?php echo $coll->user_realname ?></td>
                <?php else: ?>
				<td width="30%"><?php echo $coll->username ?></td>
                <?php endif; ?>

                <?php if(strlen($coll->user_cellphone)> 0): ?>
				<td width="30%"><?php echo $coll->user_cellphone ?></td>
                <?php else: ?>
				<td width="30%"><?php echo $coll->username ?></td>
                <?php endif; ?>

				<td width="30%"><?php echo $coll->user_officetel  ?></td>
				<td><a href="<?php echo url('user/edit', array('user_id' => $coll->id())); ?>">[编辑]</a></td>
			</tr>
		<?php endforeach; ?>	

		<input type="hidden" value="<?php echo ($num + 1); ?>" id="hid">
	</tbody>
	</table>
</form>
<?php $this->_control('pagination', 'my-pagination', array('pagination' => $pagination)); ?>
<script>
	function SelectAll() {
	 var flg=0;
	 var checkboxs=document.getElementsByName("checkboxid");
	 var count=0;
	 for (var j=0; j<checkboxs.length; j++)
	 {
		var e=checkboxs[j];
		if(e.checked)count++;
	 }
	 if(count < checkboxs.length)
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =1;
			 flg= true;
		 }
	 }
	 else 
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =0;
			 flg= false;
		 }

	 }

	 if (flg)
	 {
		document.mainform.choseall.value = "取消";
	 }
	 else
	 {
		document.mainform.choseall.value = "全选";
	 }

	}

	function CheckFirst()
	{
	    var count=0;
        var checkboxs=document.getElementsByName("checkboxid");
	    for (var i=0;i<checkboxs.length;i++)
		{
		    var e=checkboxs[i];
		    if(e.checked)count++;
	    }
        if(count == 0)
		{
			alert('请先选择删除条目'); 
			return false;
		}
		else
		{
            if(!confirm('您确认要删除吗?')) 
                return false;
            else
                return true; 
		}
	}
</script>

<a name="#addtel"></a>


<script language="javascript" type="text/javascript">
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
 
function callServer() {

  var tel_name = document.getElementById("1011").value;
  var tel_num = document.getElementById("1012").value;
  var tel_sequence = document.getElementById("1013").value;

  if ((tel_name == null) || (tel_num == "") || (tel_sequence == "")) { 
	  alert("请输入完整");
	  return false;
  };
  if(!IsTelephone(tel_num))
  {
	  alert("请输入正确的手机号码作为电话号码");
	  return false;
  }

  //var url = "<?php echo url('telephonebook/add'); ?>"+"&tel_name=" + escape(tel_name) + 
	  //"&tel_num=" + escape(tel_num) + "&tel_sequence=" + escape(tel_sequence);
  var url = "<?php echo url('telephonebook/add'); ?>";
  var poststr="&tel_name=" + encodeURIComponent(tel_name) + 
	  "&tel_num=" + escape(tel_num) + "&tel_sequence=" + escape(tel_sequence);

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updatePage;
  
  // Send the request
  xmlHttp.send(poststr);

  return false;
}

function IsTelephone(obj)// 正则判断
{ 
//检查是不是电话号码
	//var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/; 
	var regex = {     mobile: /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/ } 
	
	if(regex.mobile.test(obj)) 
	{ 
		return true; 
	} 
	else 
	{ 
		return false; 
	} 
} 

function updatePage() {
  if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    var response_id = xmlHttp.responseText;
	  var tel_1_name = document.getElementById("1011").value;
	  var tel_1_num = document.getElementById("1012").value;
	  var tel_1_sequence = document.getElementById("1013").value;
	  document.getElementById("1011").value = "";
	  document.getElementById("1012").value = "";
	  document.getElementById("1013").value = "0";
	  addtr(response_id, tel_1_name, tel_1_num, tel_1_sequence);
  }
}

function addtr(response_id, name, num, seq){
 var obj = document.getElementById('disp_table');//document.forms["mainform"].disp_table;//document.getElementById('disp_table')
 var rows =  document.getElementById('hid').value;
 var new_row = obj.insertRow(rows);//增加第rows行
 //alert("id:"+response_id);
 for(i=0; i<4; i++)
 {
	 var new_cell = new_row.insertCell();
	  new_cell.align="left";   
	  if(i==0)new_cell.innerHTML='<td><input type="checkbox" name="checkboxid[]" id="checkboxid" width="10%" value='+response_id+'/></td>';
	  if(i==1)new_cell.innerHTML='<td width="30%">'+name+'</td>';
	  if(i==2)new_cell.innerHTML='<td width="40%">'+num+'</td>';
	  if(i==3)new_cell.innerHTML="<td></td>";
	 document.getElementById('hid').value = parseInt(rows) + 1;
  }
}
 
</script>

<?php $this->_endblock(); ?>